<?php

use kzo\base\widgets\ui\common\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
use kzo\base\models\statics\EntityModelStatus;
use kzo\base\models\statics\OperationEvent;
use kzo\base\widgets\ui\common\grid\ActionColumn;

/* @var $this yii\web\View */
/* @var $searchModel common\models\c2\search\FeUserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model common\models\c2\search\FeUserSearch */

$this->title = Yii::t('app.c2', 'Fe Users');
$this->params['breadcrumbs'][] = $this->title;
?>
    <div class="fe-user-index">

        <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

        <?php echo GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'id' => 'fe-user-grid',
            'pjax' => true,
            'hover' => true,
            'showPageSummary' => true,
            'panel' => ['type' => GridView::TYPE_SUCCESS, 'heading' => Yii::t('app.c2', 'Items')],
            'toolbar' => [
                [
                    'content' =>
                        Html::a('<i class="fas fa-plus"></i>', ['edit'], [
                            'class' => 'btn btn-success',
                            'title' => Yii::t('app.c2', 'Add'),
                            'data-pjax' => '0',
                        ]) . ' ' .
                        // Html::button('<i class="fas fa-minus"></i>', [
                        //     'class' => 'btn btn-danger',
                        //     'title' => Yii::t('app.c2', 'Delete Selected Items'),
                        //     'onClick' => "jQuery(this).trigger('" . OperationEvent::DELETE_BY_IDS . "', {url:'" . Url::toRoute('multiple-delete') . "'});",
                        // ]) . ' ' .
                        Html::a('<i class="fas fa-redo"></i>', Url::current(), [
                            'class' => 'btn btn-outline-secondary',
                            'title' => Yii::t('app.c2', 'Reset Grid')
                        ]),
                    'options' => ['class' => 'btn-group mr-2']
                ],
                '{export}',
                '{toggleData}',
            ],
            'exportContainer' => ['class' => 'btn-group mr-2'],
            'exportConfig' => [],
            'columns' => [
                ['class' => 'kartik\grid\CheckboxColumn'],
                ['class' => 'kartik\grid\SerialColumn'],
                [
                    'class' => 'kartik\grid\ExpandRowColumn',
                    'value' => function ($model, $key, $index, $column) {
                        return GridView::ROW_COLLAPSED;
                    },
                    'detail' => function ($model, $key, $index, $column) {
                        return Yii::$app->controller->renderPartial('_detail', ['model' => $model]);
                    },
                ],
                'id',
                // 'type',
                // 'attributeset_id',
                'username',
                // 'email:email',
                // 'password_hash',
                // 'auth_key',
                // 'confirmed_at',
                // 'unconfirmed_email:email',
                // 'blocked_at',
                // 'registration_ip',
                // 'registration_src_type',
                // 'flags',
                // 'level',
                [
                    'attribute' => 'level',
                    'value' => function ($model) {
                        return \common\models\c2\statics\UserLevel::getLabel($model->level);
                    }
                ],
                // 'last_login_at',
                // 'last_login_ip',
                // 'open_id',
                // 'wechat_union_id',
                // 'wechat_open_id',
                'mobile_number',
                // 'sms_receipt',
                // 'access_token',
                // 'password_reset_token',
                // 'province_id',
                // 'city_id',
                // 'district_id',
                // 'created_by',
                // 'updated_by',
                // 'status',
                // 'position',
                'created_at',
                // 'updated_at',
                [
                    'attribute' => 'status',
                    'class' => '\kartik\grid\EditableColumn',
                    'editableOptions' => [
                        'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
                        'formOptions' => ['action' => Url::toRoute('editColumn')],
                        'data' => EntityModelStatus::getHashMap('id', 'label'),
                        'displayValueConfig' => EntityModelStatus::getHashMap('id', 'label'),
                    ],
                    'filter' => EntityModelStatus::getHashMap('id', 'label'),
                    'value' => function ($model) {
                        return $model->getStatusLabel();
                    }
                ],
                [
                    'class' => ActionColumn::className(),
                    'width' => '250px',
                    'template' => '{update} {view} {add-card} {card-hold} {lesson-apply}',
                    'buttons' => [
                        'update' => function ($url, $model, $key) {
                            return Html::a('<span class="fas fa-pencil-alt"></span>', ['edit', 'id' => $model->id], [
                                'title' => Yii::t('app', 'Info'),
                                'data-pjax' => '0',
                            ]);
                        },
                        'add-card' => function ($url, $model, $key) {
                            return Html::a(Yii::t('app.c2', 'Add Cards'),
                                ['/card-hold/default/edit', 'user_id' => $model->id], [
                                    'class' => 'btn btn-success btn-sm add-card',
                                    'style' => 'font-size:12px',
                                    'title' => Yii::t('app.c2', 'Add Cards'),
                                    'data-pjax' => '0',
                                ]);
                        },
                        'card-hold' => function ($url, $model, $key) {
                            return Html::a(Yii::t('app.c2', 'Card Hold'),
                                ['/card-hold/default/index', 'CardHoldSearch[user_id]' => $model->id], [
                                    'class' => 'btn btn-primary btn-sm',
                                    'style' => 'font-size:12px',
                                    'title' => Yii::t('app.c2', 'Card Hold'),
                                    'data-pjax' => '0',
                                ]);
                        },
                        'lesson-apply' => function ($url, $model, $key) {
                            return Html::a(Yii::t('app.c2', 'Lesson Apply Record'),
                                ['/lesson-apply/default/index', 'LessonApplySearch[user_id]' => $model->id], [
                                    'class' => 'btn btn-warning btn-sm',
                                    'style' => 'font-size:12px;margin-top:5px',
                                    'title' => Yii::t('app.c2', 'Lesson Apply Record'),
                                    'data-pjax' => '0',
                                ]);
                        },
                    ]
                ],

            ],
        ]); ?>

    </div>

<?php

\yii\bootstrap4\Modal::begin([
    'id' => 'edit-content',
    'size' => 'modal-lg',
    'options' => [
        'tabindex' => false
    ]
]);
\yii\bootstrap4\Modal::end();

$js = "";

$js .= "jQuery(document).off('click', 'a.add-card').on('click', 'a.add-card', function(e) {
            e.preventDefault();
            jQuery('#edit-content').modal('show').find('.modal-content').html('" . Yii::t('app.c2', 'Loading...') . "').load(jQuery(e.currentTarget).attr('href'));
        });";


$this->registerJs($js);